package com.wodsy.phoenix.datadao.goodsc.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.wodsy.phoenix.datadao.base.BaseHibernateDao;
import com.wodsy.phoenix.datadao.goodsc.dao.AreaDictDao;
import com.wodsy.phoenix.dataobject.goodsc.model.AreaDict;

/**
 * 
 * @ClassName: AreaDictDaoImpl
 * @Description: 城市字典dao实现类
 * @author ydh
 * @date 2015年3月17日 上午11:45:13
 *
 */
@Repository("areaDictDao")
public class AreaDictDaoImpl extends BaseHibernateDao<AreaDict, Long> implements AreaDictDao {
	
	@Override
	@Autowired
	@Qualifier(value = "goodsc")
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public Class<AreaDict> getModelClass() {
		return AreaDict.class;
	}

	public List<AreaDict> findByCityId(int cityId) {
		Session session = sessionFactory.openSession();
		session.beginTransaction();
		
		Query query = session.createSQLQuery("select * from tb_area_dict where FIND_IN_SET(pid, queryAreaInfo(" + cityId + "));");
		@SuppressWarnings("unchecked")
		List<AreaDict> list = query.list();
		System.out.println("-------------------------------------" + list.size());
		return list;
	}
}
